import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {AuthService} from "@shared/service/auth/auth.service";
import {TacticalService} from "@train/tactical/tactical.service";
import {Subject} from "rxjs/Rx";

@Component({
  selector: 'seed-train-tactical-type',
  templateUrl: './tactical-type.component.html',
  styleUrls: ['./tactical-type.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TrainTacticalTypeComponent implements OnInit, OnDestroy {
  public params = {
    sportType: '',
    orgUserId: ''
  };
  public ngUnsubscribe: Subject<void> = new Subject<void>();
  public typeArr: any;
  constructor(
    private activatedRoute: ActivatedRoute,
    private authService: AuthService,
    private tacticalService: TacticalService,
  ) {
    activatedRoute.params.subscribe(param => {
      this.params.sportType = param['type'];
      this.params.orgUserId = authService.getAuthOrgId();
      this.fetchSportTypeList();
      // this.fetchSportType();
    });
  }

  /**
   * @author 欧晓辉
   * @time 2018/3/9
   * @description 获取战术板运动类型
   */
  fetchSportTypeList() {
    this.tacticalService.findSportTypeList(this.params.sportType, this.params.orgUserId)
      .takeUntil(this.ngUnsubscribe)
      .subscribe(res => {
        if (res.result === '0' && res.data) {
          this.typeArr = res.data;
        }
      });
  }
  /**
   * @author 欧晓辉
   * @time 2018/3/9
   * @description 获取对象的keys
   */
  getKeys(obj) {
    return Object.keys(obj);
  }
  ngOnInit() {
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

}
